package org.spring.springboot.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.spring.springboot.po.ExitlistPO;
import org.spring.springboot.result.R;
import org.spring.springboot.result.Result;
import org.spring.springboot.server.ExitlistService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import sun.management.resources.agent;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@Api(tags = "出门单")
@RequestMapping("/exitList")
public class ExitlistController {
    @Autowired
    private ExitlistService exitlistService;

    @ApiOperation(value = "新增出门单")
    @PostMapping("/addExitList")
    public Result addExitList(@RequestBody ExitlistPO el){
        exitlistService.addExitList(el);
        return Result.newSuccessResult(el);
    }

    @ApiOperation(value = "出门单管理")
    @PostMapping("/selectByExit")
    public R selectByExit(Integer pageNum, Integer pageSize){
        Page page = PageHelper.startPage(pageNum, pageSize);
        List<Map<String, Object>> maps = exitlistService.selectByExitlist();
        Long total = page.getTotal();
        return R.newSuccessResult(maps,total);
    }

    @ApiOperation(value = "出门单详情")
    @PostMapping("/selectById")
    public Result selectById(){
        return Result.newSuccessResult(exitlistService.selectById());
    }

    @ApiOperation("出门单审批人意见")
    @PostMapping("/updateApproveOpinion")
    public Result updateApproveOpinion(@RequestParam(value = "approver") String approver,
                                       @RequestParam(value = "approveTel") String approveTel,
                                       @RequestParam(value = "approveOpinion") Integer approveOpinion,
                                       @RequestParam(value = "remark") String remark,
                                       @RequestParam(value = "id") Integer id){
        exitlistService.updateApproveOpinion(approver, approveTel, approveOpinion, remark, id);
        return Result.newSuccessResult(" id:"+id+"approver:"+approver+" approveTel:"+approveTel+
               " approveOpinion:"+approveOpinion+" remark:"+remark);
    }

    @ApiOperation(value = "出门单管理已审批")
    @PostMapping("/selectOpinion1")
    public R selectOpinion1(Integer pageNum, Integer pageSize){
        Page page = PageHelper.startPage(pageNum, pageSize);
        List<Map<String, Object>> maps = exitlistService.selectOpinion01();
        Long total = page.getTotal();
        return R.newSuccessResult(maps, total);

    }
    @ApiOperation(value = "出门单管理待审批")
    @PostMapping("/selectOpinion2")
    public R selectOpinion2(Integer pageNum, Integer pageSize){
        Page page = PageHelper.startPage(pageNum, pageSize);
        List<Map<String, Object>> maps = exitlistService.selectOpinionNull();
        Long total = page.getTotal();
        return R.newSuccessResult(maps, total);
    }

    @ApiOperation(value = "出门单待审批数量")
    @GetMapping ("/selectNumberNull")
    public Result selectNumberNull(){
        return Result.newSuccessResult(exitlistService.selectNumberNull());
    }

    @ApiOperation(value = "出门单已审批数量")
    @GetMapping ("/selectNumber01")
    public Result selectNumber01(){
        return Result.newSuccessResult(exitlistService.selectNumber01());
    }

    @PostMapping("/deleteExit")
    @ApiOperation(value = "删除出门单管理记录")
    public Result deleteExit(@RequestParam(value = "id") Integer id){
        exitlistService.deleteExitUser(id);
        return Result.newSuccessResult("删除id:"+id);
    }

    @PostMapping("/updateExit")
    @ApiOperation(value = "修改出门单管理记录")
    public Result updateExit(@RequestParam(value = "id") Integer id,
                             @RequestParam(value = "agent") String agent,
                             @RequestParam(value = "agent_tel") String agent_tel,
                             @RequestParam(value = "department") String department,
                             @RequestParam(value = "approver") String approver,
                             @RequestParam(value = "approve_tel") String approve_tel){
        exitlistService.updateExitUser(id,agent,agent_tel,department,approver,approve_tel);
        return Result.newSuccessResult("id:"+id+" agent:"+agent+" agent_tel:"+agent_tel+" department:"+department+" approver:"+approver+" approver_tel:"+approve_tel);
    }
}
